#include "map_grid.h"

MapGrid::MapGrid(uint32_t index, uint32_t status)
    : index_(index), status_(status) {} 

MapGrid::~MapGrid() {}

void MapGrid::Init(uint32_t status) { status_ = status; }

void MapGrid::SetStatus(uint32_t status) { status_ = status; }

bool MapGrid::CheckStatus(uint32_t check_type) const {
  return (status_ & check_type) != 0;
}

bool MapGrid::AddEntity(EntityPtr entity) {
  assert(entity);
  entities_.push_back(std::move(entity));
  return true;
}

void MapGrid::RemoveEntity(uint64_t id) {
  auto it = entities_.begin();
  while (it != entities_.end()) {
    if ((*it)->GetEntityId() != id) {
      ++it;
      continue;
    }
    it = entities_.erase(it);
  }
}

std::string MapGrid::ToString() const {
  return std::string("index_:{}, status_:{}", index_, status_);
}

void MapGrid::OnEndRegion() { entities_.clear(); }
